import React from 'react'
import Child from './Child'
import {Button} from 'antd'
import './style.less'

export default class Life extends React.Component {

    constructor(){
        super();
        this.state = {
            count : 0,
            name : 'Jack'
        }
    }

    // 加bind
    handleAdd() {
        this.setState({
            count : this.state.count +1,
        })
    }

    // 不加bind
    handleClick = () => {
        this.setState({
            count : this.state.count -1,
        })
    };

    render(){
        let style = {
          padding : 50
        };
        // style={style} === style={{padding:50}}
        return (
            <div style={style}>
                <p>React 声明周期介绍</p>
                <Button onClick={this.handleAdd.bind(this)}>加</Button>
                <Button onClick={this.handleClick}>减</Button>  {/*不加bind(this)*/}
                <p>{this.state.count}</p>
                <Child name={this.state.name} />
            </div>
        )
    }
}
